<?php
namespace plugins\aliyuncs;

use cmf\lib\Plugin;

class AliyuncsPlugin extends Plugin {

	public $info = [
		'name' => 'Aliyuncs',
		'title' => '阿里云存储',
		'description' => '阿里云OSS对象存储服务',
		'status' => 1,
		'author' => 'forpastime',
		'version' => '1.0',
	];

	public $hasAdmin = 0; //插件是否有后台管理界面

	// 插件安装
	public function install() {
		$storageOption = cmf_get_option('storage');
		if (empty($storageOption)) {
			$storageOption = [];
		}

		$storageOption['storages']['Aliyuncs'] = ['name' => '阿里云OSS存储', 'driver' => '\\plugins\\aliyuncs\\lib\\Aliyuncs'];

		cmf_set_option('storage', $storageOption);
		return true; //安装成功返回true，失败false
	}

	// 插件卸载
	public function uninstall() {
		return false;
		$storageOption = cmf_get_option('storage');
		if (empty($storageOption)) {
			$storageOption = [];
		}

		unset($storageOption['storages']['Aliyuncs']);

		cmf_set_option('storage', $storageOption);
		return true; //卸载成功返回true，失败false
	}

	public function fetchUploadView(&$param) {
		$config = $this->getConfig();

		$host = $config['protocol'] . '://' . $config['bucket'] . '.' . $config['endpoint'];
		$this->assign('access_host', $host);
		return $this->fetch('uploader');
	}

	public function cloudStorageTab(&$param) {

	}

}